package biz.datalk.industrialland.admin.modules.system.controller;

import biz.datalk.industrialland.admin.modules.system.pojo.dto.SysDictItemDTO;
import biz.datalk.industrialland.admin.modules.system.service.ISysDictItemService;
import biz.datalk.industrialland.common.encrypt.annotation.RSAES;
import biz.datalk.industrialland.common.json.annotation.Json;
import biz.datalk.industrialland.common.log.aspect.annotation.SysLog;
import biz.datalk.industrialland.common.log.def.OptEnum;
import biz.datalk.industrialland.common.result.UnifyResult;
import biz.datalk.industrialland.common.validated.*;
import biz.datalk.industrialland.mbg.pojo.po.SysDictItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tarofang@163.com
 * @date 2019-12-23
 */
@RestController
@RequestMapping("/sys/dictItem")
public class SysDictItemContrller {

    private final ISysDictItemService sysDictItemService;

    @Autowired
    public SysDictItemContrller(ISysDictItemService sysDictItemService) {
        this.sysDictItemService = sysDictItemService;
    }

    @RSAES
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @Json(type = SysDictItem.class, filter = "createTime,updateTime")
    @SysLog(OptEnum.LAND_DICT_10907)
    public UnifyResult list(@RequestBody @Validated(CusList.class) SysDictItemDTO sysDictItemDTO) {
        return sysDictItemService.list(sysDictItemDTO);
    }

    @RSAES
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10908)
    public UnifyResult add(@RequestBody @Validated({Insert.class}) SysDictItemDTO sysDictItemDTO) {
        return sysDictItemService.add(sysDictItemDTO);
    }

    @RSAES
    @PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10909)
    public UnifyResult edit(@RequestBody @Validated({Update.class}) SysDictItemDTO sysDictItemDTO) {
        return sysDictItemService.edit(sysDictItemDTO);
    }

    @RSAES
    @PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10910)
    public UnifyResult delete(@RequestBody @Validated({Delete.class}) SysDictItemDTO sysDictItemDTO) {
        return sysDictItemService.delete(sysDictItemDTO);
    }

    @RSAES
    @PostMapping(value = "/batchDelete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10911)
    public UnifyResult batchDelete(@RequestBody @Validated({BatchDelete.class}) SysDictItemDTO sysDictItemDTO) {
        return sysDictItemService.batchDelete(sysDictItemDTO);
    }

    @RSAES
    @PostMapping(value = "/restDel", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10912)
    public UnifyResult restDel(@RequestBody SysDictItemDTO sysDictItemDTO) {
        return sysDictItemService.restDel(sysDictItemDTO);
    }
}
